@using CleanArchitecture.Blazor.Application.Features.SiteConfigurations.Commands.AddEdit
@using SixLabors.ImageSharp
@using SixLabors.ImageSharp.Formats
@using SixLabors.ImageSharp.Processing
@inherits MudComponentBase
@inject IStringLocalizer<SiteConfigurations> L
<MudDialog>
    <DialogContent>
        <MudForm Model="model" @ref="form" Validation="@(modelValidator.ValidateValue)">
            <MudGrid>
                <MudItem xs="12">
                    <Blazor.Server.UI.Components.AutoComplete.AssignSiteIdAutocomplete
                                  Label="@L["Select Site"]" @bind-Value="model.SiteId"
                                  For="@(() => model.SiteId)"
                                  Required="true"
                                  RequiredError="@L["site is required!"]"
                                  >
                    </Blazor.Server.UI.Components.AutoComplete.AssignSiteIdAutocomplete>
                </MudItem>
                <MudItem xs="12">
                   <MudTextField Label="@L["Description"]" @bind-Value="model.Description"
                                  For="@(() => model.Description)"
                                  >
                    </MudTextField>
                </MudItem>
                <MudItem xs="12">
                   <MudCheckBox Label="@L["Mandatory Health QrCode"]" @bind-Checked="model.MandatoryHealthQrCode"
                                For="@(() => model.MandatoryHealthQrCode)"
                                  >
                   </MudCheckBox>
                </MudItem>
                <MudItem xs="12">
                   <MudCheckBox Label="@L["Mandatory Trip Code"]" @bind-Checked="model.MandatoryTripCode"
                                For="@(() => model.MandatoryTripCode)"
                                  >
                   </MudCheckBox>
                </MudItem>
                <MudItem xs="12">
                   <MudCheckBox Label="@L["Mandatory Nucleic Aacid Test Report"]" @bind-Checked="model.MandatoryNucleicAcidTestReport"
                                For="@(() => model.MandatoryNucleicAcidTestReport)"
                                  >
                   </MudCheckBox>
                </MudItem>
                <MudItem xs="12">
                   <MudTextField Label="@L["Parameters"]" @bind-Value="model.Parameters"
                                 Lines="3"
                                  For="@(() => model.Parameters)"
                                  >
                    </MudTextField>
                </MudItem>
            </MudGrid>
        </MudForm>
    </DialogContent>
    <DialogActions>
        <MudButton OnClick="Cancel">@L["Cancel"]</MudButton>
        <MudButton Color="MudBlazor.Color.Primary" OnClick="Submit">@L["Ok"]</MudButton>
    </DialogActions>
</MudDialog>

@code {
    MudForm form = default!;
    [CascadingParameter]
    MudDialogInstance MudDialog { get; set; } = default!;
    AddEditSiteConfigurationCommandValidator modelValidator = new();
    [EditorRequired] [Parameter] public AddEditSiteConfigurationCommand model { get; set; } = default!;

    async Task Submit()
    {
        await form.Validate();
        if (form.IsValid)
        {
            MudDialog.Close(DialogResult.Ok(true));
        }

    }
    void Cancel() => MudDialog.Cancel();
}
